package com.example.tests;

import java.util.Set;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import org.testng.annotations.Test;


public class GroupCreationTests extends TestBase {
	
	@Test(dataProvider = "randomGroups")
	public void testNewGroupCreation(GroupObject validGroup) throws Exception {
		// (GroupObject validGroup, String xxx) see DP commented ex
		Set<GroupObject> oldList = app.getGroupHelper().getGroups();
		//start action
		app.getGroupHelper().createGroup(validGroup);
		//verification
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		//TODO assertThat(newList, equalTo(oldList.withAddred(validGroup))); think 'bout implementation
		verifyGroupAdded(oldList, validGroup, newList);
	}
	//move it to TestBase for GroupModTests
	private void verifyGroupAdded(Set<GroupObject> oldList,
			GroupObject validGroup, Set<GroupObject> newList) {
		assertThat(newList.size(), equalTo(oldList.size()+1));
		validGroup.setId("$$$");
		oldList.add(validGroup);
		validGroup.setId(null);
		assertThat(newList, equalTo(oldList));
		//assertThat(newList.size(), equalTo(oldList.size()+1));
	}

	@Test 
	public void testNewGroupCreationWithEmptyData() throws Exception {
			GroupObject emptyDataGroup = new GroupObject()
		.setName("").setHeader("").setFooter("");
			
		Set<GroupObject> oldList = app.getGroupHelper().getGroups();
		app.getGroupHelper().createGroup(emptyDataGroup);
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		verifyGroupAdded(oldList, emptyDataGroup, newList);
		//validate
	}
}
